package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Random;
import org.testng.annotations.Test;
import com.example.utils.SortedListOf;

public class ContactModificationTests extends TestBase {

  @Test(dataProvider = "randomValidContactGenerator")
  public void testContactModification(ContactData contact) throws Exception {
    
    // save old state
    SortedListOf<ContactData> oldlist = app.getContactHelper().getContacts();
    
    Random rnd = new Random();
    int index = rnd.nextInt(oldlist.size()-1);
    
    //action
    app.getContactHelper().modifyContact(index, contact);
    
    //save new state
    SortedListOf<ContactData> newlist = app.getContactHelper().getContacts();
 	 
    //compare states
    assertThat(newlist, equalTo(oldlist.without(index).withAdded(contact)));
    }
  
}